package test;

import java.awt.EventQueue;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;import java.io.Reader;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import java.awt.BorderLayout;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import com.ibm.icu.util.CharsTrie.Iterator;

import domain.Student;
import tools.FileTool;

import java.awt.Color;
import javax.swing.JScrollBar;
import javax.swing.JSlider;

public class Table {

	private JFrame frame;
	private JTable table;
	private Vector<Student> Data=FileTool.getData();//从文件中拿数据

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Table window = new Table();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	/**
	 * Create the application.
	 * @throws IOException 
	 */
	public Table() throws IOException {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 * @throws IOException 
	 */

	private void initialize() throws IOException {
		frame = new JFrame();
		frame.setBounds(100, 100, 714, 460);
		//frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(0, 73, 696, 340);
		frame.getContentPane().add(scrollPane);
		
		table = new JTable();
		table.setBackground(Color.WHITE);
		
		//初始化表项,实例表项
		Vector Title=new Vector<String>();
		Title.add("学号");
		Title.add("姓名");
		Title.add("课程");
		Title.add("班级");
		Title.add("成绩");//初始化标题
		
		Vector data=new Vector<>();
		for(Student s:Data) {
			Vector rows=new Vector<>();
			rows.add(s.getID());rows.add(s.getName());rows.add(s.getCourse());rows.add(s.getClasses());rows.add(s.getScore());
			data.add(rows);
			DefaultTableModel model = new DefaultTableModel(data,Title);
			table.setModel(model);
		}
		
		
//		Vector Data=new Vector<>();
//		Vector rows=new Vector<>();
//		rows.add("101");rows.add("张三");rows.add("数据结构");rows.add("大数据1班");rows.add(99);
	
//		
//		Data.add(rows);
		

		scrollPane.setViewportView(table);
		
		
		frame.setVisible(true);
	}

}
